package com.pacy.pacybaseproject.constviews;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;


import com.pacy.pacybaseproject.R;

import io.reactivex.annotations.Nullable;

/**
 * @author PACY
 * @date 2024/1/16
 * description:
 */
public class AcProgressView extends LinearLayout {
    private ImageView proIv1,proIv2,proIv3;
    private TextView line1,line2,state1,state2,state3;
    private int state=0;
    public AcProgressView(Context context) {
        super(context);
    }

    public AcProgressView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        LayoutInflater.from(context).inflate(R.layout.ac_progress_view, this, true);
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AcProgressView);
        state = a.getInt(R.styleable.AcProgressView_acState,0);
        a.recycle();
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        proIv1=findViewById(R.id.proIv1);
        proIv2=findViewById(R.id.proIv2);
        proIv3=findViewById(R.id.proIv3);
        line1=findViewById(R.id.line1);
        line2=findViewById(R.id.line2);
        state1=findViewById(R.id.state1);
        state2=findViewById(R.id.state2);
        state3=findViewById(R.id.state3);
        setState(state);
    }

    public void setState(int state){
        this.state=state;

        if(state>0){
            proIv1.setImageResource(R.drawable.ac_pro_success);
            state1.setText("已完成");
//            proIv1.setImageResource(R.drawable.ac_pro_fail);
//            line1.setBackgroundColor(Color.parseColor("#D8D8D8"));
//            state1.setText("未完成");
        }
        if(state>1){
            proIv2.setImageResource(R.drawable.ac_pro_success);
            line1.setBackgroundColor(Color.parseColor("#87E34A"));
            state2.setText("已完成");
        }

        if(state>2){
            proIv3.setImageResource(R.drawable.ac_pro_success);
            line2.setBackgroundColor(Color.parseColor("#87E34A"));
            state3.setText("已完成");
        }
//        switch (this.state){
//            case 0:
//                proIv1.setImageResource(R.drawable.ac_pro_fail);
//                line1.setBackgroundColor(Color.parseColor("#D8D8D8"));
//                state1.setText("未完成");
//            case 1:
//                proIv1.setImageResource(R.drawable.ac_pro_success);
//                line1.setBackgroundColor(Color.parseColor("#87E34A"));
//                state1.setText("已完成");
//            case 2:
//            case 3:
//        }
    }
}
